package com.sugar.real.estate.module.system.api.auth;

import com.sugar.real.estate.framework.common.util.object.BeanUtils;
import com.sugar.real.estate.module.system.api.auth.dto.AppAuthDTO;
import com.sugar.real.estate.module.system.enums.logger.LoginLogTypeEnum;
import com.sugar.real.estate.module.system.service.auth.AdminAuthService;
import com.sugar.real.estate.module.system.service.user.AdminUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author Y.sugar
 * @since 2024/8/8 15:23
 */
@Service
public class AuthApiImpl implements AuthApi{

    @Resource
    private AdminAuthService authService;
    @Resource
    private AdminUserService userService;

    @Override
    public AppAuthDTO appLogin(Long userId, String username) {
        return BeanUtils.toBean(authService.appCreateTokenAfterLoginSuccess(userId, username, LoginLogTypeEnum.LOGIN_SOCIAL), AppAuthDTO.class);
    }

    @Override
    public boolean isPasswordMatch(String rawPassword, String encodedPassword) {
        return userService.isPasswordMatch(rawPassword, encodedPassword);
    }
}
